import cv2 as cv

#加载训练数据集文件
recogizer=cv.face.LBPHFaceRecognizer_create()
recogizer.read('trainer/mytrainer.yml')
#准备识别的图片
img=cv.imread('data/my-test/1.jpg')
gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
face_detector = cv.CascadeClassifier('data/haarcascade_frontalface_default.xml')
faces = face_detector.detectMultiScale(gray)
for x,y,w,h in faces:
    cv.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
    #人脸识别
    id,confidence=recogizer.predict(gray[y:y+h,x:x+w])
    #如果训练数据里有，置信评分则为0
    print('标签id:',id,'置信评分：',confidence)
cv.imshow('result',img)
cv.waitKey(0)
cv.destroyAllWindows()